<?php
/* ******************************
	Main aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action = $_REQUEST['act'];
	$user_id	= $_SESSION['USERID'];
	$error  = '';
	$sum	= 0;
	if ($_REQUEST[status]==1) {
	     $status="AND client.legal_status IN (2)";
	}else{
	    $status="AND client.legal_status NOT IN (2)";
	}
	
	switch ($action) {
		case 'get_edit_page':
			$wareHouseID	= $_REQUEST['id'];
			$page 			= GetInvoicePage($wareHouseID);
			$data			= array('page'	=> $page);

			break;
		case 'get_list':
			$client_id	= $_REQUEST['id'];
			$count = $_REQUEST['count'];
			$hidden = $_REQUEST['hidden'];
			$rResult = mysql_query("
                        SELECT 	`warehouse`.`id`,
                        		CONCAT( '№: ბ-',`a_letter`.`id`),
                        		`a_letter`.`fact_end_date`,
                        		SUM(COALESCE(b_letter_details.price,0))
                        FROM 		`a_letter`
                        left JOIN 	`client_objects` ON `client_objects`.`id` = `a_letter`.`client_object_id`
                        left JOIN 	`client` ON `client`.`id` = `client_objects`.`client_id`
                        left JOIN 	`warehouse` ON `a_letter`.`id` = `warehouse`.`a_letter_id`
                        left JOIN 	`warehouse_detail` ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` and warehouse_detail.actived = 1 AND warehouse_detail.type!=2
                        left JOIN	 b_letter_details 	ON b_letter_details.warehouse_detail_id = warehouse_detail.id AND a_letter.id=b_letter_details.a_letter_id
                        WHERE 	`client`.`id` = '$client_id'  AND `a_letter`.`b_letter_status` = 1 AND  ISNULL(`a_letter`.`invoice_id`)  AND `a_letter`.`status` >3 && a_letter.invoice_status!=20
                        GROUP BY 	`a_letter`.`id`
                        UNION
                        SELECT `warehouse`.`id`,
                        		CONCAT( '№: ე-',`d_letter`.id),
                        		DATE(`d_letter`.`fact_end_date`),
                        		SUM(COALESCE(e_letter_details.price,0))
                        FROM 	`d_letter`
                        left JOIN 	`client_objects` ON `client_objects`.`id` = `d_letter`.`client_object_id`
                        left JOIN 	`client` ON `client`.`id` = `client_objects`.`client_id`
                        left JOIN 	`warehouse` ON `d_letter`.`id` = `warehouse`.`d_letter_id`
                        left JOIN 	`warehouse_detail` ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` AND warehouse_detail.type!=2
                        left JOIN	 e_letter_details 	ON e_letter_details.warehouse_detail_id = warehouse_detail.id AND d_letter.id=e_letter_details.d_letter_id
                        WHERE 	`client`.`id` = '$client_id'  AND `d_letter`.`e_letter_status` = 1 AND ISNULL(`d_letter`.`invoice_id`) AND `d_letter`.`status` >3 && d_letter.invoice_status!=20
                        GROUP BY 	`d_letter`.`id`");

			$data = array(
					"aaData"	=> array()
			);

			if(!$rResult){
				$error = 'Invalid query: ' . mysql_error();
			}else{
				while ( $aRow = mysql_fetch_array( $rResult ) )
				{
					$row = array();
					for ( $i = 0 ; $i < $count ; $i++ )
					{
						/* General output */
						$row[] = $aRow[$i];
						if($i == ($count - 1)){
							$row[] = '<input type="checkbox" name="check_' . $aRow[$hidden] . '" class="check" value="' . $aRow[$hidden] . '" checked/>';
						}
					}
					$data['aaData'][] = $row;
				}
			}

			break;
		case 'get_invoice_form':
			$client_id	= $_REQUEST['id'];
			$amount		= $_REQUEST['amount'];
			$page 		= GetPage($client_id, $amount);
			$data		= array('page'	=> $page);

			break;
		case 'clients':
    	    $count = $_REQUEST['count'];

    	    $rResult = mysql_query("
                             SELECT	client.`id`,
                    				client.`name`,			
                    				        SUM(COALESCE((IF(warehouse_detail.type=2 AND b_letter_details.part_type_id=2,0.00,b_letter_details.price)),e_letter_details.price,0))
                    FROM		client
                    JOIN client_objects 	ON `client`.`id` = `client_objects`.`client_id`
                    JOIN warehouse 			  ON warehouse.`client_object_id` = client_objects.id
                    JOIN warehouse_detail ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` and warehouse_detail.actived = 1 AND warehouse_detail.type !=2
                    LEFT JOIN	a_letter ON a_letter.id = warehouse.a_letter_id AND a_letter.`status`>3 AND a_letter.id >2000 AND ISNULL( `a_letter`.`invoice_id` )
                    LEFT JOIN	d_letter ON d_letter.id = warehouse.d_letter_id AND d_letter.`status`>3 AND d_letter.id >100  AND ISNULL( `d_letter`.`invoice_id` )
                    LEFT JOIN	b_letter_details ON b_letter_details.warehouse_detail_id = warehouse_detail.id AND a_letter.id=b_letter_details.a_letter_id
                    LEFT JOIN	e_letter_details ON e_letter_details.warehouse_detail_id = warehouse_detail.id AND d_letter.id=e_letter_details.d_letter_id
                    WHERE (NOT ISNULL(warehouse.d_letter_id) OR NOT ISNULL(warehouse.a_letter_id)) $status
                    GROUP BY `client`.`id`");

			$data = array(
				"aaData"	=> array()
			);

			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
				    if ($i==1) {
				        $row[] ="<p title='$aRow[$i]'>$aRow[$i]<p>";
				    }else 
					$row[] = $aRow[$i];
				}
				$data['aaData'][] = $row;
			}

			break;
	    case 'signed':
    	    $count = $_REQUEST['count'];
    	    $id = $_REQUEST['id'];

    	    $rResult = mysql_query("SELECT 		`warehouse`.`id`,
                        			CONCAT( '№: ბ-',`a_letter`.`id`),
                        			DATE(`a_letter`.`fact_end_date`),
    	                            CONCAT('<p title=\"', a_letter.end_date,'\">', DATE(a_letter.end_date),'</p>'),  
                        			CONCAT('<p title=\"',client_objects.`name`,'\">',client_objects.`name`,'</p>'), 
                        			SUM(COALESCE(b_letter_details.price,0))
                        FROM 		`a_letter`
                        JOIN 	`client_objects` 	ON `client_objects`.`id` = `a_letter`.`client_object_id`
                        JOIN 	`client` 			ON `client`.`id` = `client_objects`.`client_id`
                        JOIN 	`warehouse` 		ON `a_letter`.`id` = `warehouse`.`a_letter_id` AND a_letter.actived=1
                        JOIN 	`warehouse_detail` 	ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` AND warehouse_detail.actived=1 AND warehouse_detail.type!=2
                        JOIN	 b_letter_details 	ON b_letter_details.warehouse_detail_id = warehouse_detail.id AND a_letter.id=b_letter_details.a_letter_id
                        WHERE	`client`.`id` = '$id'  AND  a_letter.`status`>3 AND a_letter.id >2000 AND ISNULL(`a_letter`.`invoice_id`) AND `a_letter`.`b_letter_status` = 1
                        GROUP BY 	`a_letter`.`id`
                        UNION
                        SELECT 	    `warehouse`.`id`,
                        			CONCAT( '№: ე-',`d_letter`.id),
                        			DATE(`d_letter`.`fact_end_date`),    	                           
    	                            CONCAT('<p title=\"', d_letter.end_date,'\">', DATE(d_letter.end_date),'</p>'),    
                        			CONCAT('<p title=\"',client_objects.`name`,'\">',client_objects.`name`,'</p>'), 
                        			SUM(COALESCE(e_letter_details.price,0))
                        FROM 		`d_letter`
                        JOIN 	`client_objects`  ON `client_objects`.`id` = `d_letter`.`client_object_id`
                        JOIN 	`client`          ON `client`.`id` = `client_objects`.`client_id`
                        JOIN 	`warehouse`       ON `d_letter`.`id` = `warehouse`.`d_letter_id` AND d_letter.actived=1
                        JOIN 	`warehouse_detail` ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` AND warehouse_detail.actived=1 AND warehouse_detail.type!=2
                        JOIN	 e_letter_details ON e_letter_details.warehouse_detail_id = warehouse_detail.id AND d_letter.id=e_letter_details.d_letter_id
                        WHERE	 `client`.`id` = '$id'  AND d_letter.`status`>3 AND d_letter.id >100  AND ISNULL(`d_letter`.`invoice_id`) AND `d_letter`.`e_letter_status` = 1
                        GROUP BY 	`d_letter`.`id`");

			$data = array(
				"aaData"	=> array()
			);

			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					//General output
					$row[] = $aRow[$i];
				}
				$data['aaData'][] = $row;
			}

	        break;
	    case 'unsigned':
    	    $count = $_REQUEST['count'];
    	    $id = $_REQUEST['id'];
		    $rResult = mysql_query("SELECT 		`warehouse`.`id`,
                        			CONCAT( '№: ბ-',`a_letter`.`id`),
                        			DATE(`a_letter`.`fact_end_date`),
                        			client_objects.`name`,
                        			SUM(COALESCE(b_letter_details.price,0))
                        FROM 		`a_letter`
                        JOIN 	`client_objects` 	ON `client_objects`.`id` = `a_letter`.`client_object_id`
                        JOIN 	`client` 			ON `client`.`id` = `client_objects`.`client_id`
                        JOIN 	`warehouse` 		ON `a_letter`.`id` = `warehouse`.`a_letter_id` AND a_letter.actived=1
                        JOIN 	`warehouse_detail` 	ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` AND warehouse_detail.actived=1 AND warehouse_detail.type!=2
                        JOIN	 b_letter_details 	ON b_letter_details.warehouse_detail_id = warehouse_detail.id AND a_letter.id=b_letter_details.a_letter_id
                        WHERE	 `client`.`id` = '$id' AND a_letter.`status`>3 AND a_letter.id >2000 AND ISNULL(`a_letter`.`invoice_id`) AND `a_letter`.`b_letter_status` != 1
                        GROUP BY 	`a_letter`.`id`
                        UNION
                        SELECT 	    `warehouse`.`id`,
                        			CONCAT( '№: ე-',`d_letter`.id),
                        			DATE(`d_letter`.`fact_end_date`),
                        			client_objects.`name`,
                        			SUM(COALESCE(e_letter_details.price,0))
                        FROM 		`d_letter`
                        JOIN 	`client_objects`  ON `client_objects`.`id` = `d_letter`.`client_object_id`
                        JOIN 	`client`          ON `client`.`id` = `client_objects`.`client_id`
                        JOIN 	`warehouse`       ON `d_letter`.`id` = `warehouse`.`d_letter_id` AND d_letter.actived=1
                        JOIN 	`warehouse_detail` ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` AND warehouse_detail.actived=1 AND warehouse_detail.type!=2
                        JOIN	 e_letter_details ON e_letter_details.warehouse_detail_id = warehouse_detail.id AND d_letter.id=e_letter_details.d_letter_id
                        WHERE	 `client`.`id` = '$id' AND d_letter.`status`>3 AND d_letter.id >100  AND ISNULL(`d_letter`.`invoice_id`) AND `d_letter`.`e_letter_status` != 1
                        GROUP BY 	`d_letter`.`id`");

			$data = array(
				"aaData"	=> array()
			);

			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$data['aaData'][] = $row;
			}

	        break;

	        case 'signed_all':
	        	$count = $_REQUEST['count'];
	        	$id = $_REQUEST['id'];
	        	
$rResult = mysql_query("SELECT 		`warehouse`.`id`,
                        			CONCAT( '№: ბ-',`a_letter`.`id`),
                        			DATE(`a_letter`.`fact_end_date`),
                                    CONCAT('<p title=\"', a_letter.end_date,'\">', DATE(a_letter.end_date),'</p>'),  
                        			CONCAT('<p title=\"',client_objects.`name`,'\">',client_objects.`name`,'</p>'),     
                        			SUM(COALESCE(b_letter_details.price,0))
                        FROM 		`a_letter`
                        JOIN 	`client_objects` 	ON `client_objects`.`id` = `a_letter`.`client_object_id`
                        JOIN 	`client` 			ON `client`.`id` = `client_objects`.`client_id`
                        JOIN 	`warehouse` 		ON `a_letter`.`id` = `warehouse`.`a_letter_id` AND a_letter.actived=1
                        JOIN 	`warehouse_detail` 	ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` AND warehouse_detail.actived=1 AND warehouse_detail.type!=2
                        JOIN	 b_letter_details 	ON b_letter_details.warehouse_detail_id = warehouse_detail.id AND a_letter.id=b_letter_details.a_letter_id
                        WHERE	a_letter.`status`>3 AND a_letter.id >2000 AND ISNULL(`a_letter`.`invoice_id`) AND `a_letter`.`b_letter_status` = 1 $status
                        GROUP BY 	`a_letter`.`id`
                        UNION
                        SELECT 	    `warehouse`.`id`,
                        			CONCAT( '№: ე-',`d_letter`.id),
                        			DATE(`d_letter`.`fact_end_date`),
                                    CONCAT('<p title=\"', d_letter.end_date,'\">', DATE(d_letter.end_date),'</p>'),                       			
                                    CONCAT('<p title=\"',client_objects.`name`,'\">',client_objects.`name`,'</p>'),         
                        			SUM(COALESCE(e_letter_details.price,0))
                        FROM 		`d_letter`
                        JOIN 	`client_objects`  ON `client_objects`.`id` = `d_letter`.`client_object_id`
                        JOIN 	`client`          ON `client`.`id` = `client_objects`.`client_id`
                        JOIN 	`warehouse`       ON `d_letter`.`id` = `warehouse`.`d_letter_id` AND d_letter.actived=1 
                        JOIN 	`warehouse_detail` ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` AND warehouse_detail.actived=1 AND warehouse_detail.type!=2 
                        JOIN	 e_letter_details ON e_letter_details.warehouse_detail_id = warehouse_detail.id AND d_letter.id=e_letter_details.d_letter_id
                        WHERE	 d_letter.`status`>3 AND d_letter.id >100  AND ISNULL(`d_letter`.`invoice_id`) AND `d_letter`.`e_letter_status` = 1 $status
                        GROUP BY 	`d_letter`.`id`");

	        			$data = array(
	        	"aaData"	=> array()
	        	);

			while ( $aRow = mysql_fetch_array( $rResult ) )
	        			{
	        			$row = array();
	        			for ( $i = 0 ; $i < $count ; $i++ )
	        			{
	        			/* General output */
	        			$row[] = $aRow[$i];
	        				}
	        				$data['aaData'][] = $row;
	        	}



	        	break;

	case 'unsigned_all':
	        		$count = $_REQUEST['count'];
	        		$id = $_REQUEST['id'];

	        		$rResult = mysql_query("SELECT 		`warehouse`.`id`,
                                            			CONCAT( '№: ბ-',`a_letter`.`id`),
                                            			DATE(`a_letter`.`fact_end_date`),
                                            			client_objects.`name`,
                                            			SUM(COALESCE(b_letter_details.price,0))
                                            FROM 		`a_letter`
                                            JOIN 	`client_objects` 	ON `client_objects`.`id` = `a_letter`.`client_object_id`
                                            JOIN 	`client` 			ON `client`.`id` = `client_objects`.`client_id`
                                            JOIN 	`warehouse` 		ON `a_letter`.`id` = `warehouse`.`a_letter_id`
                                            JOIN 	`warehouse_detail` 	ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` AND warehouse_detail.actived=1 AND warehouse_detail.type!=2
                                            JOIN	 b_letter_details 	ON b_letter_details.warehouse_detail_id = warehouse_detail.id AND a_letter.id=b_letter_details.a_letter_id
                                            WHERE	a_letter.`status`>3 AND a_letter.actived=1 AND a_letter.id >2000 AND ISNULL(`a_letter`.`invoice_id`) AND `a_letter`.`b_letter_status` != 1 $status
                                            GROUP BY 	`a_letter`.`id`
                                            UNION
                                            SELECT 	    `warehouse`.`id`,
                                            			CONCAT( '№: ე-',`d_letter`.id),
                                            			DATE(`d_letter`.`fact_end_date`),
                                            			client_objects.`name`,
                                            			SUM(COALESCE(e_letter_details.price,0))
                                            FROM 		`d_letter`
                                            JOIN 	`client_objects`  ON `client_objects`.`id` = `d_letter`.`client_object_id`
                                            JOIN 	`client`          ON `client`.`id` = `client_objects`.`client_id`
                                            JOIN 	`warehouse`       ON `d_letter`.`id` = `warehouse`.`d_letter_id`
                                            JOIN 	`warehouse_detail` ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id` AND warehouse_detail.actived=1 AND warehouse_detail.type!=2 
                                            JOIN	 e_letter_details ON e_letter_details.warehouse_detail_id = warehouse_detail.id AND d_letter.id=e_letter_details.d_letter_id
                                            WHERE	 d_letter.`status`>3 AND d_letter.actived=1 AND d_letter.id >100  AND ISNULL(`d_letter`.`invoice_id`) AND `d_letter`.`e_letter_status` != 1 $status
                                            GROUP BY 	`d_letter`.`id`
	        				");

	        				$data = array(
	        		"aaData"	=> array()
	        		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
        				{
        				$row = array();
        				for ( $i = 0 ; $i < $count ; $i++ )
        				{
        				/* General output */
        				$row[] = $aRow[$i];
        					}
        					$data['aaData'][] = $row;
        		}

		break;
    default:
       $error =  "null";
}


$data['error'] = $error;

echo json_encode( $data );

function GetPage($client_id, $amount){
	$result	=	 mysql_fetch_array(mysql_query("SELECT	client.`name` as `name`
												FROM	client
												WHERE	client.id = '$client_id'"));
	$data = '
		<div id="dialog-form">
			<fieldset>
				<legend>ძირითადი ინფორმაცია</legend>
				<table width="80%" class="dialog-form-table" cellpadding="10px" >
					<tr align="center">
						<th colspan="2">
							<label for="client_object">კლიენტი  :&nbsp;&nbsp;&nbsp;&nbsp;</label>'.$result['name'].'
						</th>
					</tr>
					<tr align="center">
						<th colspan="2">
							<label for="client_object">ჯამური თანხა :&nbsp;&nbsp;&nbsp;&nbsp;</label>'.$amount.'
						</th>
					</tr>
				</table>
			</fieldset>

			<div class="clear"></div>
			<fieldset>
		    	<legend>კატრიჯები</legend>
				 <div class="produse">
				    <div class="inner-table">
					    <div id="dt_example" class="ex_highlight_row">
					        <div id="container" class="overhead_container">
					        	<div id="button_area">
					        	</div>
					            <div id="dynamic">
					                <table class="display" id="prod_list" >
					                    <thead>
						                        <tr id="datatable_header">
						                            <th>ID</th>
						                            <th style="width: 170px">ბარათის N</th>
						                            <th style="width: 170px">თარიღი</th>
						                            <th style="width: 100%">თანხა</th>
			                           				<th class="check">#</th>
						                        </tr>
					                    </thead>
										<thead>
							                     <tr class="search_header">
							                            <th class="colum_hidden">
							                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
							                            </th>
							                            <th>
							                            	<input type="text" name="search_letter" value="ფილტრი" class="search_init" />
							                            </th>
														<th>
															<input type="text" name="search_date" value="ფილტრი" class="search_init" />
														</th>
														<th>
															<input type="text" name="search_amount" value="ფილტრი" class="search_init" />
														</th>
							                            <th>
							                            	<input type="checkbox" name="check-all" id="check-all" checked>
							                            </th>
							                     </tr>	
					                    </thead>							    
					                    <tfoot>
					                        <tr>
					                            <th>&nbsp;</th>
					                            <th>&nbsp;</th>
												<th><p align="right">ჯამი:<br/>სულ ჯამი:</th>
												<th>&nbsp;</th>
					                            <th>&nbsp;</th>
					                        </tr>
					                    </tfoot>
					                </table>
					            </div>
					        </div>
					    </div>
					</div>
				</div>
			</fieldset>
		<!-- ID -->
    </div>
	<div class="inner-table">
		<input type="hidden" style="" name="search_id" class="search_init"  id="client_id" value="'.$client_id.'"/>
	</div';
	return $data;
}

function print1($letterID, $type){
	global $sum;
	$data = '';
	if( $type == 2 ){
		$rsql = mysql_query("SELECT	printer_parts_type.`name`,
                            		production.`name`,
                            		barcodes.serial_number,
                            		COALESCE(e_letter_details.price,'0.00')
                            FROM    e_letter_details
                            JOIN	warehouse_detail ON warehouse_detail.id	= e_letter_details.warehouse_detail_id and warehouse_detail.actived = 1 AND warehouse_detail.type !=2
                            LEFT JOIN	production ON production.id = warehouse_detail.prod_id
		                    LEFT JOIN barcodes ON barcodes.`code` = warehouse_detail.barcode  
                            LEFT JOIN	printer_parts_type ON printer_parts_type.id = e_letter_details.part_type_id
                            WHERE		e_letter_details.d_letter_id = '$letterID'");
	}else{
		$rsql = mysql_query("SELECT  cartridge_parts_type.`name`,
                            			production.`name`,
                            			b_letter_details.barcode,
                            			IF(warehouse_detail.type!=2,b_letter_details.price,'0.00')
                            FROM    	b_letter_details
                            JOIN	warehouse_detail ON warehouse_detail.id	= b_letter_details.warehouse_detail_id and warehouse_detail.actived = 1 
                            LEFT JOIN	production ON production.id = warehouse_detail.prod_id 
                            LEFT JOIN	cartridge_parts_type ON cartridge_parts_type.id = b_letter_details.part_type_id 
                            WHERE		b_letter_details.a_letter_id = '$letterID' ");

	}

	while ( $aRow = mysql_fetch_array( $rsql ) ){
		$data .= '<tr style=" height: 25px !important;">';
		for ( $i = 0 ; $i < 4 ; $i++ ){
			$data .='<td  style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
			if( $i == 3){
				$sum = floatval($sum) + floatval($aRow[$i]);
			}

		}
		//echo $sum; return 0;
		$data .= '</tr>';
	}
	return $data;
}

function addNull($sum){
	if($sum != '' && $sum != '0'){
		$parts = explode('.', $sum);
		$sum1 ='';
		$sum1.= $parts[0];
		if( $parts[1] == ''){
			$sum1.= '.00';
		}else{
			$sum1 = $sum;
		}
		return $sum1;
	}else{
		return '0.00';
	}
}

function GetInvoicePage($wareHouseID){
	global $sum;
	$result	=	 mysql_fetch_array(mysql_query("SELECT		`client`.`id` as `client_id`,
															`client`.`name` as `name`,
															`warehouse`.`a_letter_id` as `a_letter`,
															`warehouse`.`d_letter_id` as `d_letter`
												FROM		`warehouse`
												LEFT JOIN	`client_objects` ON `client_objects`.`id` = `warehouse`.`client_object_id`
												LEFT JOIN	`client` ON `client`.`id` = `client_objects`.`client_id`
												WHERE		`warehouse`.id = '$wareHouseID'"));
	$letterID = '';
	$letter = '';
	$type = '';
	$client_id = $result['client_id'];
	if($result['a_letter'] != ''){
		$letter = '№: ა -' . $result['a_letter'];
		$letterID = $result['a_letter'];
		$type = 1;
	}else{
		$letter = '№: დ -' . $result['d_letter'];
		$letterID = $result['d_letter'];
		$type = 2;
	}
	$data='
	<div id="dialog-form">
		<fieldset>
				<legend>ძირითადი ინფორმაცია</legend>
				<table width="80%" class="dialog-form-table" cellpadding="10px" >
					<tr align="center">
						<th>
							<label for="client_object">კლიენტი  :&nbsp;&nbsp;&nbsp;&nbsp;</label>'.$result['name'].'
						</th>
						<th>
							<label for="client_object">ბარათი  :&nbsp;&nbsp;&nbsp;&nbsp;</label>'.$letter.'
						</th>
					</tr>
				</table>
		</fieldset>
		<fieldset style="margin-top: 4px;">
					<table style="width: 545px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
						<tr style="background-color: black !important; border:1px solid black !important; color: white !important; height: 25px !important;">
							<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>სერვისი</span></td>
							<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
							<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">შტრიხკოდი</td>
							<td style="width: 10% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">ფასი</td>
						</tr>';
	$data .= print1($letterID, $type);
	$data .= '
					</table>
					<table>
						<div style="text-align: right; font-size: 10pt; margin-top: 4px;">
							<p>თანხა სულ :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;">' . addNull($sum) . '&nbsp;&nbsp;ლარი</span></p>
						</div>
					</table>
		</fieldset>
    </div>
	<div class="inner-table" >
		<input type="hidden" id="client_id" value="' . $client_id . '" />
	</div>
	<div class="inner-table" >
		<input type="hidden" id="warehouseID" value="' . $wareHouseID . '" />
	</div>';
	return $data;
}
?>